define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'users/index',
        add_url: 'users/add',
        edit_url: 'users/edit',
        export_url: 'users/export',
        modify_url: 'users/modify',
        password_url: 'users/password',
        true_delete_url: 'users/true_delete',
        restore_url: 'users/restore',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh',
                    [{
                        text: '添加',
                        url: init.add_url,
                        method: 'open',
                        auth: 'add',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-plus ',
                        extend: 'data-full="true"',
                    }], 'export'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'uid', title: '员工ID', hide: true, search: false},
                    {field: 'job_number', title: '工号'},
                    {field: 'true_name', title: '真实姓名'},
                    {field: 'phone', title: '手机号'},
                    {field: 'gender', search: 'select', selectList: ["女","男"], title: '性别'},
                    {field: 'age', title: '年龄', search: false},
                    {field: 'base_salary', title: '基本工资', search: false},
                    {field: 'entry_date', title: '入职日期', search: 'range'},
                    {field: 'status', search: 'select', selectList: ["正常","离职"], title: '状态', templet: function (d) {
                            if (d.status == 0){
                                return '<div class="layui-table-cell" style="color: green;">正常</div>';
                            }
                            return '<div class="layui-table-cell" style="color: red;">离职</div>';
                        }
                    },
                    {
                        width: 200,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '编辑',
                                url: init.edit_url,
                                method: 'open',
                                auth: 'edit',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                                extend: 'data-full="true"',
                                field: 'uid'
                            },{
                                text: '设置密码',
                                url: init.password_url,
                                method: 'open',
                                auth: 'password',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                                field: 'uid'
                            }]
                        ]
                    }

                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        password: function () {
            ea.listen();
        }
    };
    return Controller;
});